package uk.org.scuts.bantstadium2.attacks;

import java.util.Random;

import uk.org.scuts.bantstadium2.Character;

public class Intimidate extends Attack {

	// Constructors
	public Intimidate() {
		_name = "Intimidate";
		_criticalRequirement = 10.0;
		_hitRequirement = 1.0;
	}

	public String Execute(Character user, Character target) {
		String log = (user.Name() + " tries to intimidate " + target.Name());
		switch (Hits(user, target)) {
		case MISS: 
			log += (" but isn\'t scary enough. ");
		    break;
		case GLANCING:
			log += (" but just makes " + target.ObjPronoun() + " angrier. ");
			log += target.Enrage(1);
		    break;
		case NORMAL: 
			log += (" and scares " + target.ObjPronoun() + ". ");
        	log += target.Depress(3);
        	break;
		case CRITICAL: 
			log += (" and terrifies " + target.ObjPronoun() + ". ");
			log += target.Surrender();
			break;
		}
		return log;
	}	
	
	hitType Hits(Character user, Character target) {
		if (user.Attack() < target.Defense()) {
			return hitType.MISS;
		} else if (target.Defense() <= 0) {
			return hitType.CRITICAL;
		} else {
			double rand = new Random().nextInt(100);
			double hitAccuracy = _accuracy * (Math.sqrt(user.Attack())/Math.sqrt(target.Defense()));
			double hitRatio = hitAccuracy / rand;
			if (hitRatio > _criticalRequirement) {
				return hitType.CRITICAL;
			} else if (hitRatio > _hitRequirement) {
				return hitType.NORMAL;
			} else {
				return hitType.GLANCING;
			}
		}
	}
}
